package hyj.qx.kuaican.service.impl;

import hyj.qx.kuaican.model.CyOrder;
import hyj.qx.kuaican.model.Item;
import hyj.qx.kuaican.model.Order;
import hyj.qx.kuaican.model.OrderStatus;
import hyj.qx.kuaican.service.OrderRepository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MemoryOrderRepository implements OrderRepository {
    private static final Map<String, Order> orders = new ConcurrentHashMap<>();
    private static final Map<String, Order> orderMap = new ConcurrentHashMap<>();
    private static final Map<String, CyOrder> cyorderMap = new ConcurrentHashMap<>();



    @Override
    public void save(Order order) {
        orders.put(order.getOrderId(), order);
    }

    @Override
    // 根据订单ID查找订单
    public Order findById(String orderId) {
        // 从订单列表中获取指定ID的订单
        return orders.get(orderId);
    }

    @Override
    public Order findUpOrderById(String orderId) {
        return orderMap.get(orderId);
    }

    @Override
    public void updateStatus(String orderId, OrderStatus status) {
        Order order = orders.get(orderId);
        if (order != null) {
            order.setStatus(status);
        }
    }

    @Override
    public void removeOrder(String orderId) {
        orders.remove(orderId);
    }


    @Override
    public Order addOrderMap(String orderId, Order order) {
        orderMap.put(orderId, order);
        return order;
    }

    @Override
    public CyOrder addCyOrderMap(String orderId, CyOrder cyOrder) {
        cyorderMap.put(orderId, cyOrder);
        return cyOrder;
    }

    @Override
    public List<CyOrder> findCyOrder() {
        return new ArrayList<>(cyorderMap.values());
    }
}
//    @Override
//    public Order addItems(String orderId, List<Item> items, boolean vip) {
//        Order order = orders.get(orderId);
//        String id = order.getOrderId();
//        List<Item> itemList = order.getItems();
//        itemList.addAll(items);
//        Order order1 = orderService.createOrder(itemList,vip);
//        if (order1 != null){
//            order1.setOrderId(id);
//            orderMap.put(id,order1);
//            return order1;
//        }
//        return order;
//    }
//}